<template>
  <div>
    <f-table ref='table' rowKey='orderDetailsId' :columns='columns' :scroll='{x:true}'
             handler='noSbReturnPageListHandler' :showMultipleBtn='false' :multiple='multiple' :operator='operator'
             :params='queryParam' :api='api.bod'>
     <span slot='action' slot-scope='text, record'>
          <template>
             <a @click='$refs.orderInfoDrawer.showDrawer(record)'>查看</a>
          </template>
        </span>
    </f-table>
    <sbreturn-drawer ref='sbreturnDrawer' @success='onLoad'></sbreturn-drawer>
    <order-info-drawer ref='orderInfoDrawer'></order-info-drawer>
  </div>
</template>
<script>
import api from './../js/api'
import SbreturnDrawer from './sbreturn_drawer'
import OrderInfoDrawer from '@/views/module/business/order/order_info_drawer'

export default {
  name: 'SbreturnNo',
  components: { OrderInfoDrawer, SbreturnDrawer },
  data() {
    let me = this
    //操作按钮
    let operator = []
    operator.push({
      name: '申请退垫付款',
      icon: 'transaction',
      that: this,
      handler: function(table, that) {
        let selectIds = table.selectedRowKeys
        if (selectIds.length > 0) {
          let supplierBond = table.getSelectedTotal('supplierPayBond')
          me.$refs['sbreturnDrawer'].showDrawer({
            supplierBond: supplierBond,
            selectIds: selectIds.join(','),
            supplierId: me.supplierId
          }, 'form1')
        } else {
          if (!that.queryParam.supplierId) {
            that.$message.error('请选择供货方')
            return
          }
          that.$message.error('请选择退款明细')
        }
      }
    })
    return {
      api: Object.assign(api, this.api),
      multiple: false,
      supplierId:'',
      //列表初始化查询参数
      queryParam: {},
      returnCustomBond: 0,
      selectIds: '',
      params1: {
        supplierId: ''
      },
      // 表头
      columns: [
        {
          title: '#',
          width: '60px',
          align: 'center',
          customRender: (text, record, index) => index + 1
        },
        {
          title: '操作',
          align: 'center',
          width: '80px',
          scopedSlots: { customRender: 'action' }
        },
        {
          title: '单号',
          align: 'left',
          width: '120px',
          dataIndex: 'orderNo'
        },
        {
          title: '发货日期',
          align: 'left',
          width: '100px',
          dataIndex: 'sendDate'
        },
        {
          title: '供货方',
          align: 'left',
          width: '150px',
          ellipsis: true,
          dataIndex: 'supplierName'
        },
        {
          title: '购货方',
          align: 'left',
          width: '150px',
          ellipsis: true,
          dataIndex: 'customName'
        },
        {
          title: '商品名称',
          align: 'left',
          width: '150px',
          ellipsis: true,
          dataIndex: 'drugsName'
        },
        {
          title: '规格',
          align: 'left',
          width: '100px',
          dataIndex: 'drugsSpec'
        },
        {
          title: '数量',
          align: 'left',
          width: '60px',
          dataIndex: 'saleNum'
        },
        {
          title: '单价',
          align: 'left',
          width: '60px',
          dataIndex: 'salePrice'
        },
        {
          title: '回款金额',
          align: 'left',
          width: '60px',
          dataIndex: 'returnAmount'
        },
        {
          title: '回款日期',
          align: 'left',
          width: '60px',
          dataIndex: 'returnDate'
        },
        {
          title: '垫付金额',
          align: 'left',
          width: '80px',
          needTotal: true,
          dataIndex: 'supplierPayBond'
        },
        {
          title: '垫付日期',
          align: 'left',
          width: '120px',
          dataIndex: 'supplierBondPayDate'
        }
      ],
      operator: operator
    }
  },
  created() {
  },
  methods: {
    setData() {
    },
    //部门切换
    deptChange(value) {
      this.queryParam.deptId = value
      this.$refs.table.refresh(false)
    },
    /**
     * 查询事件
     * @param searchParams
     */
    searchTable(searchParams) {
      if (searchParams.supplierId) {
        this.multiple = true
        this.$refs.table.openMultiple()
      } else {
        this.multiple = false
        this.$refs.table.closeMultiple()
      }
      this.queryParam = Object.assign(this.queryParam, searchParams)
      this.$refs.table.refresh(true, searchParams)
    },
    openMultiple(searchParams) {
      if (searchParams.supplierId) {
        this.supplierId = searchParams.supplierId
        this.multiple = true
        this.$refs.table.openMultiple()
      } else {
        this.multiple = false
        this.$refs.table.closeMultiple()
      }
    },
    /**
     * 刷新列表
     */
    onLoad() {
      this.$refs.table.refresh()
      this.$emit('changeTab')
    }
  }
}
</script>
